package com.msmall.community.admin.action;

import java.io.File;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantDB;
import com.msmall.community.common.model.Commend;
import com.msmall.community.common.service.CommendManager;

public class CommendAction extends HTMLBaseAction {

	private static final long serialVersionUID = 8395050717467271917L;

	private Long commendid;
	
	private String commendIds;
	
	/**
	 * 当推荐需要图片时，上传
	 */
	private File image;
	private String imageContentType; // 文件的内容类型
	private String imageFileName; // 上传文件名
	
	private Commend commend;
	
	private CommendManager commendManager;

	public String execute(){
		return SUCCESS;
	}
	public String query(){
		try{
		page.setPageSize(1000);
		page.setClazz(Commend.class);
		StringBuffer buffer = new StringBuffer();
		buffer.append(" from Commend where 1=1 ");
		if(commend != null){
			if(commend.getCommendDisplay() > 0){
				buffer.append(" and commendDisplay=").append(commend.getCommendDisplay());
			}else{
				buffer.append(" and commendDisplay=").append(ConstantDB.COMMEND_DISPLAY_0);
			}
			if(commend.getCommendType() > 0){
				buffer.append(" and commendType=").append(commend.getCommendType());
			}
			
		}
		page.setQueryString(buffer.toString());
		commendManager.getPagination(page);
		}catch(Exception e){
			log.debug(e);
		}
		return SUCCESS;
	}
	public String update(){
		setCommend((Commend)commendManager.get(Commend.class, commendid));
		return SUCCESS;
	}
	
	public String save(){
		if(commend.getEnabled() == null){
			commend.setEnabled(ConstantDB.UNAVALIABLE);
		}
		commendManager.auditCommend(image, imageFileName, commend, getUserid(), getUserAgentType());
		return SUCCESS;
	}
	public String remove(){
		commendManager.removeCommends(commendIds, getUserid());
		return SUCCESS;
	}
	public Long getCommendid() {
		return commendid;
	}

	public void setCommendid(Long commendid) {
		this.commendid = commendid;
	}

	public String getCommendIds() {
		return commendIds;
	}

	public void setCommendIds(String commendIds) {
		this.commendIds = commendIds;
	}

	public Commend getCommend() {
		return commend;
	}

	public void setCommend(Commend commend) {
		this.commend = commend;
	}

	public File getImage() {
		return image;
	}

	public void setImage(File image) {
		this.image = image;
	}

	public String getImageContentType() {
		return imageContentType;
	}

	public void setImageContentType(String imageContentType) {
		this.imageContentType = imageContentType;
	}

	public String getImageFileName() {
		return imageFileName;
	}

	public void setImageFileName(String imageFileName) {
		this.imageFileName = imageFileName;
	}

	public void setCommendManager(CommendManager commendManager) {
		this.commendManager = commendManager;
	}
	
}
